//
//  EnSureAlipayViewController.swift
//  E-CycleForShop
//
//  Created by enghou on 17/3/11.
//  Copyright © 2017年 xyxorigation. All rights reserved.
//

import UIKit

class EnSureAlipayViewController: BaseViewController {

    var amount = ""
    var type = -1 //0支付宝1微信
    var account = ""
    override func viewDidLoad() {
        super.viewDidLoad()
        self.naviHide = false
        self.title = "确认提现"
        self.defaultBackButton()
        self.rightButton(title: "完成", target: self, selector: #selector(done))
        configView()
    }
    
    func configView() -> Void {
        self.view.backgroundColor = UIColor.colorWithHexString(hex: "f3f3f5")
        let imageView = UIImageView.init(frame: CGRect.init(x: (YXDeviceWidth-300*YXWidthScale)/2, y: 60*YXHeightScale, width: 300*YXWidthScale, height: 300*YXHeightScale))
        let image = UIImage.load(name: "icon_withdrawals")
        imageView.image = image
        self.view.addSubview(imageView)
        let label = UILabel.init()
        label.textColor = UIColor.colorWithHexString(hex: "2c2c2c")
        label.text = "提现申请已提交，预计两个工作日到账"
        label.font = UIFont.systemFont(ofSize: 32 * YXWidthScale)
        let size = label.text!.StringSize(font: label.font)
        label.frame = CGRect.init(x: YXDeviceWidth / 2 - size.width / 2, y: imageView.bottom() + 18 * YXHeightScale, width: size.width, height: size.height)
        self.view.addSubview(label)
        
        let tray = UIView.init()
        tray.frame = CGRect.init(x: 30 * YXWidthScale, y: 442 * YXHeightScale, width: YXDeviceWidth - 60 * YXWidthScale, height: 462 * YXHeightScale)
        tray.backgroundColor = UIColor.white
        tray.layer.cornerRadius = YXButtonCorner
        tray.layer.borderColor = UIColor.colorWithHexString(hex: "dfdfdf").cgColor
        tray.layer.borderWidth = YXHeightScale
        self.view.addSubview(tray)
        let lbl = UILabel.init()
        lbl.frame = CGRect.init(x: 32 * YXWidthScale, y: 32 * YXHeightScale, width: 150, height: 30)
        lbl.font = UIFont.systemFont(ofSize: 28 * YXWidthScale)
        lbl.text = "提现金额"
        tray.addSubview(lbl)
        
        let amountLbl = UILabel.init()
        let font = UIFont.boldSystemFont(ofSize: 56 * YXWidthScale)
        let font1 = UIFont.systemFont(ofSize: 32 * YXWidthScale)
        let size1 = amount.StringSize(font: font)
        let size2 = "元".StringSize(font: font1)
        amountLbl.frame = CGRect.init(x: YXDeviceWidth / 2 - size1.width / 2 - size2.width / 2, y: 124 * YXHeightScale, width: size1.width, height: size1.height)
        amountLbl.font = font
        amountLbl.text = amount
        tray.addSubview(amountLbl)
        let yuan = UILabel.init()
        yuan.frame = CGRect.init(x: amountLbl.right(), y: amountLbl.top() + 0.3 * amountLbl.height(), width: size2.width, height: size2.height)
        yuan.text = "元"
        yuan.font = font1
        tray.addSubview(yuan)
        
        let line = UIView.init()
        line.backgroundColor = UIColor.colorWithHexString(hex: "ececec")
        line.frame = CGRect.init(origin: CGPoint.init(x: 32 * YXWidthScale, y: 218 * YXHeightScale), size: CGSize.init(width: 1000, height: YXHeightScale))
        tray.addSubview(line)
        let str = ((type == 0) ? "支付宝" : "微信")
        let vi1 = view(title: "到账方式: ", content: str ,origin : CGPoint.init(x: 32 * YXWidthScale, y: line.bottom() + 48 * YXHeightScale))
        tray.addSubview(vi1)
        
        let vi2 = view(title: "申请用户: ", content: account ,origin : CGPoint.init(x: 32 * YXWidthScale, y: vi1.bottom() + 30 * YXHeightScale))
        tray.addSubview(vi2)
        let date = Date.init(timeIntervalSinceNow: 0.0)
        let formatter = DateFormatter.init()
        formatter.locale = Locale.init(identifier: "zh_CN")
        formatter.dateFormat = "yyyy.MM.dd HH:mm"
        let s = formatter.string(from: date)
        let vi3 = view(title: "提现时间: ", content: s,origin : CGPoint.init(x: 32 * YXWidthScale, y: vi2.bottom() + 30 * YXHeightScale))
        tray.addSubview(vi3)
    }
    
    func view(title : String,content : String,origin : CGPoint) -> UIView {
        let tray = UIView.init()
        let font = UIFont.systemFont(ofSize: 28 * YXWidthScale)
        let size = title.StringSize(font: font)
        let titleLbl = UILabel.init()
        titleLbl.frame = CGRect.init(origin: CGPoint.zero, size: size)
        titleLbl.textColor = UIColor.colorWithHexString(hex: "646464")
        titleLbl.font = font
        titleLbl.text = title
        tray.addSubview(titleLbl)
        
        let cnt = UILabel.init()
        cnt.text = content
        cnt.textColor = titleLbl.textColor
        cnt.font = font
        let size1 = content.StringSize(font: font)
        cnt.frame = CGRect.init(origin: CGPoint.init(x: titleLbl.right(), y: titleLbl.top()), size: size1)
        tray.addSubview(cnt)
        tray.frame = CGRect.init(origin: origin, size: CGSize.init(width: size.width + size1.width, height: size.height))
        return tray
    }
    
    @objc func done() -> Void {
        if let vc = self.navigationController?.childViewControllers[1] {
            let _ = self.navigationController?.popToViewController(vc, animated: true)
        }
    }
    
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

}
